package com.guaoran.micro.services.spring.boot.actuator.service;

import com.guaoran.micro.services.spring.boot.actuator.domain.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

/**
 * @Author gucheng
 * @Description test
 * 2019-07-11 9:41
 */
@Service
public class TestService {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    public void save(Test test){
        jdbcTemplate.update("INSERT INTO test (name,age) VALUES(?,?)",new Object[]{test.getName(),test.getAge()});
    }
    public Test getTest(Long id){
        Test test = jdbcTemplate.queryForObject("SELECT * FROM test WHERE id = ?", new Object[]{id}, new BeanPropertyRowMapper<Test>(Test.class));
        return test;
    }
}
